const app = getApp()
Page({

  data: {
      pageNane:"testPreview",
      maskShow: false,
      title:'',
      euaid:'',
      tokenID:'',
      moment:[],
      trueorfalseCounter:0,
      singleCounter:0,
      multiCounter:0,
      fillCounter:0,
      essCounter:0,
      sumnum:0,
      percent:'',
      totalcredit:0,
      truenum:0,
      falsenum:0,
      passScore:0,
      pass:false,
      user:'',
      lblBai:'',
      showBai:false,
      lblShi:'',
      showShi: false,
      lblGe:'',
      showGe: false,
      bar_contact:false
  },
  onLoad: function (options) {
      var _this = this;
      _this.setData({
          title: options.title,
          euaid: options.euaid,
          tokenID: app.data.tokenID
      })
      wx.request({
          url: app.data.api + 'exam/showExamlib',
          method: "POST",
          data: {
              "token": _this.data.tokenID,
              "euaid": _this.data.euaid
          },
          header: { 'content-type': 'application/x-www-form-urlencoded' },
          success: function (res) {
              var testList = res.data.data.liblist;
              var moment_list = _this.data.moment;
              for (var i = 0; i < testList.length ; i++)
              {
                    var json = {};
                    json.question = testList[i].question,
                    json.counter = testList[i].counter,
                    json.options = testList[i].options,
                    json.type = testList[i].type,
                    json.rightAnswer = testList[i].rightAnswer,
                    json.userAnswer = testList[i].userAnswer,
                    json.score = testList[i].score,
                    json.userRealScore = testList[i].userRealScore,
                  json.correct = testList[i].correct;
                    moment_list.push(json);
              }
              var totalc = res.data.data.totalcredit;
              var num = totalc.toString();
              var val = [];
              for (var i = 0; i < num.length; i++) {
                  val.push(num[i])
              }
              if (val.length == 3) {
                  _this.setData({
                      lblBai: 'num' + val[0],
                      showBai:true,
                      lblShi: 'num' + val[1],
                      showShi:true,
                      lblGe: 'num' + val[2],
                      showGe: true,
                  })
              } else if (val.length == 2) {
                  _this.setData({
                      showBai: false,
                      lblShi: 'num' + val[0],
                      showShi: true,
                      lblGe: 'num' + val[1],
                      showGe: true,
                  })
              } else if (val.length == 1) {
                  _this.setData({
                      showBai: false,
                      showShi: false,
                      lblGe: 'num' + val[0],
                      showGe: true,
                  })
              }
              _this.setData({
                  allTopicnum: testList.length,
                  unfinished: testList.length,
                  moment: moment_list,
                  trueorfalseCounter: res.data.data.type_1000,
                  singleCounter: res.data.data.type_1001,
                  multiCounter: res.data.data.type_1002, 
                  fillCounter: res.data.data.type_1003, 
                  essCounter: res.data.data.type_1004,
                  sumnum: res.data.data.total, 
                  percent: res.data.data.percent, 
                  totalcredit: res.data.data.totalcredit,
                  truenum: res.data.data.truenum,
                  falsenum: res.data.data.falsenum,
                  passScore: res.data.data.plan.passScore,
                  pass: res.data.data.pass,
                  user: res.data.data.user,
              })
          }
      })

  },
    showClassification: function () {
        this.setData({
            maskShow: true
        })
    },
    cancel: function () {
        this.setData({
            maskShow: false
        })
    },
    backpage:function(){
        wx.reLaunch({
            url: '../index/index'
        })
    },
    bar_contact:function(){
        this.setData({
            bar_contact: !this.data.bar_contact
        })
    },
    toolbar_maskCancel:function(){
        this.setData({
            bar_contact: false
        })
    },
    onUnload(){
        const wxCurrPage = getCurrentPages();//获取当前页面的页面栈
        const wxPrevPage = wxCurrPage[wxCurrPage.length - 2];//获取上级页面的page对象
        if (wxPrevPage.data.pageNane == 'testPaper')
        {
            wx.navigateTo({
                url: '../examine/examine'
            })
        }
    }
})